package org.wenhuayuan.hiui.tab

import android.graphics.BitmapFactory
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_hi_tab_bottom_demo.*
import org.wenhuayuan.hiapplib.util.HiDisplayUtil
import org.wenhuayuan.hiui.R
import org.wenhuayuan.uilibrary.tab.bottom.HiTabBottomInfo

class HiTabBottomDemoAty : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_hi_tab_bottom_demo)

        initTabBottom()
    }

    private fun initTabBottom() {
        hiBottomLayout.setTabBottomAlpha(0.8f)
        val bottomInfoList = ArrayList<HiTabBottomInfo<*>>()
        val homeInfo = HiTabBottomInfo("首页",
            "fonts/iconfont.ttf",
            getString(R.string.if_home), null,
            "#ff656667",
            "#ffd44949")
        val infoCommend = HiTabBottomInfo("收藏",
            "fonts/iconfont.ttf",
            getString(R.string.if_recommend), null,
            "#ff656667",
            "#ffd44949")
//        val infoCategory = HiTabBottomInfo("分类",
//            "fonts/iconfont.ttf",
//            getString(R.string.if_category), null,
//            "#ff656667",
//            "#ffd44949")
        val infoChat = HiTabBottomInfo("推荐",
            "fonts/iconfont.ttf",
            getString(R.string.if_chat), null,
            "#ff656667",
            "#ffd44949")
        val infoProfile= HiTabBottomInfo("我的",
            "fonts/iconfont.ttf",
            getString(R.string.if_profile), null,
            "#ff656667",
            "#ffd44949")

        val bitmap = BitmapFactory.decodeResource(resources, R.drawable.road, null)
        val infoCategory = HiTabBottomInfo<String>("分类", bitmap!!, bitmap!!)
        bottomInfoList.add(homeInfo)
        bottomInfoList.add(infoCommend)
        bottomInfoList.add(infoCategory)
        bottomInfoList.add(infoChat)
        bottomInfoList.add(infoProfile)
        hiBottomLayout.inflateInfo(bottomInfoList)

        hiBottomLayout.addTabSelectedChangeListener { _, preInfo, nextInfo ->
            Log.i("HiTabBottomDemoAty1", nextInfo.name)
            preInfo?.let { Log.i("HiTabBottomDemoAty2", it.name) }
            Toast.makeText(this@HiTabBottomDemoAty, nextInfo.name, Toast.LENGTH_SHORT).show()
        }

        hiBottomLayout.defaultSelected(homeInfo)
        val tabBottomCategory = hiBottomLayout.findTab(infoCategory)
        tabBottomCategory.resetHeight(HiDisplayUtil.dp2px(70f, resources))
    }
}
